import * as type from './type'

import axios from 'axios'

const state = {
    list:{}
}

export const actionCreators = {
    get_list(val){
        return dispatch => {
            axios({
                url:'/api/getBrandGoods',
                params:{
                    page: 1,
                    brand_id: val,
                    msort: 1,
                    goods_utype: 'C4',
                    price_range: '',
                    cat_threeids: '',
                }
            }).then(data =>{
                let action = {
                    type:type.GET_LIST,
                    payload: data.data
                }
                dispatch(action)
            })
              .catch(error => console.log(error))
        }
    }
}

export const reducer = (prevState = state , action ) =>{

    const newState= {
        ...prevState
    }
    switch (action.type) {
        case type.GET_LIST:
            newState.list = action.payload;
            break;
    
        default:
            break;
    }
    return newState
}